package com.wksc.framework.impexp.reader;

import java.io.IOException;

import jxl.Cell;
import jxl.Sheet;
import jxl.Workbook;
import jxl.WorkbookSettings;
import jxl.read.biff.BiffException;

/**
 * <p> Title(文件名): XlsReader.java </p>
 * <p> Description(描述): Excel文件的读取类 </p>
 * <p> Copyright(版权): Copyright (c) 2011 </p>
 * <p> Company(公司): 成都四方信息技术有限公司 </p>
 * <p> CreateTime(生成日期)：2011-11-29 上午11:23:04 </p>
 * @author wanglei
 * @version impExp_C13_P
 */
public class XlsReader extends Reader{
	private Sheet sheet;
	private Workbook workBook;

    public XlsReader(){
    	super();
    }

    @Override
    public int countTotalLine() {
        return sheet.getRows();
    }

    @Override
    public String[] readByRow(int lineNum) {
    	int colNum = sheet.getRow(0).length;
    	String[] data = new String[colNum];
    	for(int i = 0; i < colNum; i++){
    		Cell cell = sheet.getCell(i, lineNum);
    		if(null == cell.getContents()){
    			data[i] = "";
    		}else{
    			data[i] = cell.getContents().trim();
    		}
    	}
        return data;  //To change body of implemented methods use File | Settings | File Templates.
    }

	@Override
	public void close(){
		workBook.close();
	}

	@Override
	protected void initFile() throws BiffException, IOException {
		WorkbookSettings workbookSettings = new WorkbookSettings();
		workbookSettings.setEncoding("ISO-8859-1");
		workBook = Workbook.getWorkbook(this.file, workbookSettings);
        sheet  = workBook.getSheet(0);
	}
	
}
